package com.rz.spark.tags

import org.apache.spark.sql.Row

object Tags4KeyWords  extends Tags {
  /**
    * 打标签的方法定义
    *
    * @param args
    * @return
    */
  override def makeTags(args: Any*): Map[String, Int] = {
    var map = Map[String, Int]()
    val row = args(0).asInstanceOf[Row]
    val stopWords = args(1).asInstanceOf[Map[String, Int]]

    val kws = row.getAs[String]("keywords")
    kws.trim.split("\\|", -1).filter(kw => kw.length>=3 && kw.length <=8 && !stopWords.contains(kw))
      .foreach( kw => map += "K"+kw ->1)

    map
  }
}
